package com.hand.test.controller;/**
 * @author Estelle@앙수청
 * @date 2019/7/20 9:30
 */

import com.hand.test.annotation.PermissionAnnotation;
import com.hand.test.domain.Matter;
import com.hand.test.domain.MatterStorerow;
import com.hand.test.domain.StoreDTO;
import com.hand.test.service.MatterService;
import com.hand.test.service.MatterStoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *  @author Estelle@앙수청
 *  @date 2019/7/20 9:30
 */
@RestController
@RequestMapping("/store")
public class MatterStoreController {

    @Autowired
    private MatterStoreService matterStoreService;

    @Autowired
    private  MatterService matterService;

    @GetMapping("/{matterId}")
    @PermissionAnnotation
    public ResponseEntity<StoreDTO> queryMatterStore(@PathVariable("matterId") Integer matterId){
        return ResponseEntity.ok(matterStoreService.queryMatterStore(matterId));
    }

    @GetMapping("/invalidScan")
    @PermissionAnnotation
    public ResponseEntity<Void> queryInvalidMatterStore(){
        MatterStorerow matterStorerow = matterStoreService.queryNoCount();
        Integer matterId = matterStorerow.getMatterId();
        Integer storerowId = matterStorerow.getStorerowId();

        matterService.deleteMatter(matterId);
        matterStoreService.deleteMatterStorerow(storerowId);

        return ResponseEntity.ok().build();
    }
}
